<template>
  <div o-Container>
    <o-list v-bind:source="list.contract" v-bind="{ created: create, exported: output }">
      <template slot="config" slot-scope="scope">
        <div class="img_box">
          <img @click="showLookDiaolog(scope)"
            src="../../../../../static/skin/default/MCS/AIGC/Inventory/images/chakan.png" alt="">
            <img @click="showEditDialog(scope)"
            src="../../../../../static/skin/default/MCS/AIGC/Inventory/images/bianji.png" alt="">
        </div>
      </template>
    </o-list>
    <DriverMsg ref="DriverMsg" :messageList="messageList"></DriverMsg>
    <EditDriver ref="EditDriver" :type="dialogType" :messageList="messageListAdd" @refresh="refresh"></EditDriver>
  </div>
</template>

<script>
import DriverMsg from '../Components/DriverMsg.vue'
import EditDriver from '../Components/EditDriver.vue'
export default {
    components: {
    DriverMsg,
    EditDriver
  },
  name: "mms_platform_company_list", /* 这个name暂时不知道用啥用，根据官方文档说的是方便排错的 */
  data() {
    return {
      octopus: this.$parent.octopus,
      list: {
        contract: {
          data: {
            id: 1219, // 菜单表的八爪鱼ID
            cellData: [
              {name: "Name"},	// 账号名/手机号
              {name: "Code"},	// 工号
              {name: "Mobile"},	// 手机号
              {name: "Sex"},	// 性别
              {name: "RoleID", show: false},	// 所属岗位
              {name: "CreateUserName"},	// 创建人
              {name: "CreateDate", width: 200},	// 创建时间
              {name: "Address", show: false},	// 地址
              {name: "Age", show: false},	// 年龄
              {name: "CompanyID", show: false},	// 公司ID
              {name: "CompanyName", show: false},	// 公司名
              {name: "DepartmentID", show: false},	// 部门ID
              {name: "ID", show: false},	// ID
              {name: "IdentityNumber", show: false},	// 身份证号
              {name: "RealName", show: false},	// 真实名
              {name: "NickName", show: false},	// 昵称
              {name: "TypeID", show: false},	// 人员类型
            ],
            paramData: {
              // this.octopus.passport.authorization.company
              CompanyID: 81, //调试使用
              RoleID: 141,
              Status: 1
            }
          },
          configWidth: 60,
          showNumber: true,
        },
      },
      messageList: {},
      messageListAdd: {},
      dialogType: 2,
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      const cellData = this.list.contract.data.cellData;
      // 遍历 cellData，找到符合条件的元素，并添加键值对
      cellData.forEach(item => {
        if (item.name === "CompanyID") {
          // 添加 filterKey 和 filterValue
          item.filterKey = '=';
          item.filterValue = this.octopus.passport.authorization.company == 1 ? '' : this.octopus.passport.authorization.company;
        }
      });
    },
    showLookDiaolog(row) {
      this.messageList = row.data.row
      this.$refs.DriverMsg.drawerOp()
    },
    showEditDialog(row) {
      this.dialogType = 2
      let o = this
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: "1219",
          cellData: [
            {name: "ID", filterKey: "=", filterValue: row.data.row.ID},	// ID
            {name: "RealName"},	// 真实名
            {name: "Code"},	// 工号
            {name: "Mobile"},	// 手机号
            {name: "Sex"},	// 性别
            {name: "CreateUserID"},	// 创建人
            {name: "CreateUserName"},	// 创建人
            {name: "CreateDate"},	// 创建时间
            {name: "Address"},	// 地址
            {name: "Age"},	// 年龄
            {name: "CompanyID"},	// 公司ID
            {name: "CompanyName"},	// 公司名
            {name: "DepartmentID"},	// 部门ID
            {name: "DepartmentID"}, //部门
            {name: "IdentityNumber"},	// 身份证号
            {name: "Name"},	// 账号名/手机号
            {name: "NickName"},	// 昵称
            {name: "RoleID"},	// 所属岗位
            {name: "RoleName"},	// 所属岗位
            {name: "TypeID"},	// 人员类型
            {name: "TypeName"},	// 人员类型
          ],
          paramData: {
            // this.octopus.passport.authorization.company
            CompanyID: 81, //调试使用
            RoleID: 141,
            Status: 1
          }
        },
        function (data) {
          if (data.status.code == 200) {
            o.messageListAdd = data.content.queryData[0]
            o.$refs.EditDriver.drawerOp()
          } else {
            o.octopus.tips.error(data);
          }
        });
    },
    output: function (data) {
      this.octopus.tips.success("下载完成。");
    },
    search: function (cell) {
    },
    create: function (data) {
      this.dialogType = 1
      this.messageListAdd = {}
      this.$refs.EditDriver.drawerOp()
    },
    save: function (data) { // 保存
      this.octopus.tips.success(data);
      // 刷新list
      this.list.contract.control.load();
      this.back();
    },
    back: function () {
      this.panel.visible = false;
    },
    del: function (row) {
      let o = this
      // alert("del key: " + JSON.stringify(row));
      this.$confirm('此操作将永久删除该项, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.octopus.request.api.post("/Octopus/Engine/Item", {
          id: 1188, // 菜单表的八爪鱼ID
          type: "DELETE",
          value: row.ID,
          cellData: [
            { name: "ID", defaultValue: row.ID },
          ],
        },
          // 处理回调事件，通过分析data.status.code的状态来实现。
          function (data) {
            if (data.status.code === 200) {
              o.list.contract.control.load();
            } else {
              o.octopus.tips.error(data);
            }
          }
        );
        this.$message({
          type: 'success',
          message: '删除成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    refresh() {
      this.list.contract.control.load();
    },
  },
  props: ["oData"]
}
</script>
<style scoped>
.el-message-box {
  background-color: #fff !important;
}

.img_box {
  display: flex;
  justify-content: space-between;
  width: 100%;
}

.img_box img {
  width: 25px;
  cursor: pointer;
}
</style>
